import React, {Component} from 'react';
import {List, Avatar, Button, message} from 'antd';
import storageUtil from "../../../utils/storageUtil";

class Check extends Component {

    state = {
        results: '',
        oid: ''
    }


    componentDidMount() {
        this.$myAxios.get('/user/showUnchecked').then(res => {
            console.log(res.data)
            this.setState({
                results: res.data
            })
        })

    }

    render() {


        return (
            <List
                itemLayout="horizontal"
                dataSource={this.state.results}
                renderItem={item => (
                    <List.Item>
                        <List.Item.Meta
                            avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
                            title={<a>用户名:{item.username}</a>}
                            description={"电话:"+item.phone+"  邮箱:"+item.email}
                        />

                        <Button
                            onClick={()=>{
                                console.log(item)
                                storageUtil.saveUser(item)
                                const uid = storageUtil.getUser().uid
                                this.$myAxios.get("/user/check/"+uid).then(res=>{
                                    console.log(res.data)
                                    if(res.data){
                                        message.success("审核通过")
                                        window.location.reload()
                                    }
                                    else
                                        message.error("审核失败，请重新操作")
                                })
                            }}
                            style={{marginLeft: '10px', marginRight: '10px'}}
                            type="primary"
                        >
                            审核通过
                        </Button>
                    </List.Item>
                )}
            />
        );
    }
}

export default Check;